package com.only4play.practice.common.enums.pay;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.only4play.codegen.support.constants.BaseEnum;

import java.util.Optional;

/**
 * @author mengdy
 */

public enum TradeStatusEnum implements BaseEnum<TradeStatusEnum>{

    /** SUCCESS，支付成功，说明该行数据为一笔支付成功的订单 */
    SUCCESS(100,"SUCCESS"),
    /** REFUND，转入退款，说明该行数据为一笔发起退款成功的退款单 */
    REFUND(101,"REFUND"),
    /** 关闭 */
    CLOSED(102,"CLOSED"),
    /** REVOKED，已撤销，说明该行数据为一笔在用户支付成功后发起撤销的退款单 */
    REVOKED(103,"REVOKED"),
    /** 失败 */
    FAIL(-100,"FAIL"),
    /** 异常 */
    EXCEPTION(-101,"EXCEPTION"),
    ;

    TradeStatusEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }
    @EnumValue
    private Integer code;
    //  @JsonValue
    private String name;

    @Override
    public Integer getCode() {
        return this.code;
    }

    @Override
    public String getName() {
        return this.name;
    }

    public static Optional<TradeStatusEnum> of(Integer code) {
        return Optional.ofNullable(BaseEnum.parseByCode(TradeStatusEnum.class, code));
    }
}
